﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace FinanSoft.Entities
{
    [DataContract]
    public class SaleReport
    {
        #region Attributes
        private int _clientId;
        private int _itemId;
        private DateTime _lastSaleDate;
        private double _totalQuantity;
        private double _totalSold;
        private double _invoiceAverageSold;
        private int _invoiceAmount;
        private List<SaleReportHistoryDetail> _saleHistory;
        #endregion

        #region Constructor
        public SaleReport(int clientId, int itemId, DateTime lastSaleDate, double totalQuantity, double totalSold, double invoceAverage, int invoiceAmount)
        {
            _clientId = clientId;
            _itemId = itemId;
            _lastSaleDate = lastSaleDate;
            _totalQuantity = totalQuantity;
            _totalSold = totalSold;
            _invoiceAverageSold = invoceAverage;
            _saleHistory = new List<SaleReportHistoryDetail>();
            _invoiceAmount = invoiceAmount;
        }
        #endregion

        #region Properties
        [DataMember]
        public int ClientId
        {
            get
            {
                return _clientId;
            }
            set
            {
                _clientId = value;
            }
        }
        
        [DataMember]
        public int ItemId
        {
            get
            {
                return _itemId;
            }
            set
            {
                _itemId = value;
            }
        }

        [DataMember]
        public DateTime LastSaleDate
        {
            get
            {
                return _lastSaleDate;
            }
            set
            {
                _lastSaleDate = value;
            }
        }

        [DataMember]
        public double TotalQuantity
        {
            get
            {
                return _totalQuantity;
            }
            set
            {
                _totalQuantity = value;
            }
        }

        [DataMember]
        public double TotalSold
        {
            get
            {
                return _totalSold;
            }
            set
            {
                _totalSold = value;
            }
        }

        [DataMember]
        public double InvoiceAverageSold
        {
            get
            {
                return _invoiceAverageSold;
            }
            set
            {
                _invoiceAverageSold = value;
            }
        }

        [DataMember]
        public SaleReportHistoryDetail[] SaleHistory
        {
            get
            {
                return _saleHistory.ToArray();
            }
            set
            {
                _saleHistory.Clear();
                foreach (SaleReportHistoryDetail detail in value)
                    _saleHistory.Add(detail);
            }
        }

        [DataMember]
        public int InvoiceAmount
        {
            get
            {
                return _invoiceAmount;
            }
            set
            {
                _invoiceAmount = value;
            }
        }
        #endregion

        #region Public Methods
        public void AddHistoryDetail(SaleReportHistoryDetail historyDetail)
        {
            _saleHistory.Add(historyDetail);
        }
        #endregion
    }
}
